/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package xmlparser;

import base.*;
import java.io.File;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.stream.*;
import org.xml.sax.SAXException;

/**
 *
 * @author pbelov
 */
public class Main {


    private static void println(String str) {
        System.out.println(str);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws SAXException, ParserConfigurationException, IOException {
        println("Starting test XML parser");
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser parser = factory.newSAXParser();

        //userParser userp = new userParser();
        //parser.parse(new File("users.xml"), userp);
        //User[] users = userp.getResult();
        //Tools.usersTest(users);
        bugParser bugp = new bugParser();
        Bug bug = null, bug2 = null;
        int bugn = 0;
        int bugn2 = 1;
        File bugfile = new File(Tools.getFilePath(bugn));
        File bugfile2 = new File(Tools.getFilePath(bugn2));

        // creating test bug and writing it to file
        Bug b = new Bug();
        b.createTestBug(0);
        xmlWriter xmlw = new xmlWriter(Tools.getFilePath(bugn));
        xmlWriter xmlw2 = new xmlWriter(Tools.getFilePath(bugn2));
        xmlw.createFile(b);

        // parsing test file
        if (bugfile.exists()) {
            parser.parse(bugfile, bugp);
            bug = bugp.getResult(); //geting result of parsing
        } else {
            System.err.println("File [" + bugfile + "] doesn't exists!");
        }
 
        xmlw2.createFile(bug); // creating new bug file with parsed data
    }
}
